//
//  ScrollPhotoView+Request.m
//  NaRiLSVMT
//
//  Created by zhangmeng on 14-8-15.
//  Copyright (c) 2014年 helloyouth.org. All rights reserved.
//

#import "ScrollPhotoView+Request.h"
#import "Network_Operation.h"
#import "UIImageView+AFNetworking.h"
#import "MBProgressController.h"
#import "ScrollPhotoView+AddopenView.h"
#import "ScrollPhotoView+list.h"
@implementation ScrollPhotoView (Request)
//获取所有的屏幕
-(void)getScreenRequestNum
{
    //[[MBProgressController sharedInstance] showWithText:@"正在努力加载....."];
    WeakSelf;
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    NSString *getScreenStr = [Network_API Network_API_GetScreen];
    AFHTTPClient *httpClient = [Network_Operation httpClientWithUrl:getScreenStr];
    NSDictionary *dic = @{
                          @"classname":@"iControlSolutionService",
                          @"methodname":@"getScreenForPad",
                          @"parameterClasss":@[@{
                                        @"parametername" :@"userId",
                                        @"parametervalue":subjectId,
                                        @"valuetype":@"java.lang.String"}
                                    ]
                          };
    
    [httpClient postPath:getScreenStr parameters:@{@"jsonstr":[Common dictoJson:dic],
                                                   @"callback":@""
                                                   }
                 success:^(AFHTTPRequestOperation *operation, id responseObject) {
                     NSLog(@"success");
                     wself.screenArr = [NSMutableArray array];
                     NSArray *arr = [Common jsontoArr:responseObject];
                     if(!arr.count){
                     [[MBProgressController sharedInstance] hide];
                         dispatch_async(dispatch_get_main_queue(), ^{                                    [[MBProgressController sharedInstance] showTipsOnlyText:@"当前没有管理的屏幕!" AndDelay:1.5];
                         });
                     }
                     else{
                         [[MBProgressController sharedInstance] hide];
                         dispatch_async(dispatch_get_main_queue(), ^{
                             [[MBProgressController sharedInstance] hide];
                         });
                     }
                     wself.screenArr = [NSMutableArray arrayWithArray:arr];
                    [self reloadHeadImageData:nil];
                 }
                 failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                     dispatch_async(dispatch_get_main_queue(), ^{
                         [[MBProgressController sharedInstance] hide];
                         [[MBProgressController sharedInstance] showTipsOnlyText:@"获取屏幕失败!" AndDelay:1.5];
                     });
                 }];
    
    });//
}
//根据分组获取分组下的缩略图
-(void)getScreenImage:(NSString *)screenId Numscreen:(NSInteger)nbtn GroupArr:(NSArray *)groupArr
{
    [[MBProgressController sharedInstance] showWithText:@"正在努力加载....."];
    WeakSelf;
    //解析成组的字符串
    NSString *groupstring = nil;
    if(groupArr && [groupArr count]){
        for(NSDictionary *dic in groupArr){
            NSString *tmpstr;
            if([Common isEmptyString:groupstring])
             tmpstr = [NSString stringWithFormat:@"%@",dic[@"id"]];
            else
             tmpstr = [NSString stringWithFormat:@"%@,%@",groupstring,dic[@"id"]];
            groupstring = [NSString stringWithString:tmpstr];
        }
    }
    else{
        self.labList.text = @"";
        return;
    }
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    NSString *getScreenStr = [Network_API Network_API_GetScreen];
    AFHTTPClient *httpClient = [Network_Operation httpClientWithUrl:getScreenStr];
    NSDictionary *dic = @{
                          @"classname":@"iControlSolutionService",
                          @"methodname":@"getImageFromReveTemplateByGroupId",
                          @"parameterClasss":@[@{
                                        @"parametername" :@"screenId",
                                        @"parametervalue":screenId,
                                        @"valuetype":@"java.lang.String"},
                                        @{
                                        @"parametername" :@"groupId",
                                        @"parametervalue":groupstring,
                                        @"valuetype":@"java.lang.String"
                                        }
                                    ]
                          };
    
    [httpClient postPath:getScreenStr parameters:@{@"jsonstr":[Common dictoJson:dic],
                                                   @"callback":@""
                                                   }
                 success:^(AFHTTPRequestOperation *operation, id responseObject) {
                     NSLog(@"success");
                     NSArray *arr = [Common jsontoArr:responseObject];
                    // dispatch_async(dispatch_get_main_queue(), ^{
                         [[MBProgressController sharedInstance] hide];
                    // });
                     //添加新的屏幕初始化
                    if(nbtn){
                    [self closeThumbUi];
                    [self.onceplay setBackgroundImage:[UIImage imageNamed:@"scan_onceplay.png"] forState:UIControlStateNormal];
                    [self.arrowplay setBackgroundImage:[UIImage imageNamed:@"scan_arrowplay.png"] forState:UIControlStateNormal];
                     }
                     MJCollectionViewController *collectionview = [[MJCollectionViewController alloc] init];
                     collectionview.view.frame = Frame(36,-8,self.collView.frame.Width-72,self.collView.frame.Height+10);
                     collectionview.collectionView.backgroundColor = ColorRGB(25,76,86);                     collectionview.delegate = self;
                     collectionview.thumbPage = [NSMutableArray array];
                     collectionview.thumbPage = [NSMutableArray arrayWithArray:arr];
                     collectionview.allPage = arr.count;
                     if(arr.count%collectionview.num)
                          collectionview.allPagenumber  = arr.count/collectionview.num +1 ;
                     else
                          collectionview.allPagenumber  = arr.count/collectionview.num;
                     [collectionview counstView:arr];
                     [self.collView addSubview:collectionview.view];
                     [self.collView bringSubviewToFront:collectionview.view];
                     self.collecView = collectionview;
                     //修改pageview
                     if(collectionview.allPagenumber > 1 )
                     self.pageView.numberOfPages = collectionview.allPagenumber;
                     else
                     self.pageView.numberOfPages = 0;
                     NSMutableDictionary *dic = [NSMutableDictionary dictionary];
                     self.nowScreen = nbtn;
                     //创建自己的queue
                     NSString *tmpqueue = [NSString stringWithFormat:@"%@%ld",@"queue_",(long)nbtn];
                    const char *queu = [tmpqueue UTF8String];
                     dispatch_queue_t queue = dispatch_queue_create(queu,nil);
                     dic[[NSString stringWithFormat:@"%ld",(long)nbtn]] = [NSArray arrayWithArray:arr];
                     dic[@"numscreen"] = [NSString stringWithFormat:@"%ld",(long)nbtn];
                     dic[@"screenId"] = screenId;
                     dic[@"collec"] = collectionview;
                     dic[@"noOnceplay"] = @0;
                     dic[@"noArrowplay"] = @0;
                     dic[@"noOpen"] = @0;
                     dic[@"playtime"] = @"3";
                     dic[@"queue"] = queue;
                     dic[@"startqueue"] = @"0";
                     dic[@"proharr"] = [NSArray array];
                     //加全部
                     NSMutableArray *tmpGroup = [NSMutableArray arrayWithArray:groupArr];
                     
                     if([groupArr count] >= 1){
                     NSDictionary *strDic = @{@"groupname":@"全部"};
                     [tmpGroup insertObject:strDic atIndex:0];
                         dispatch_async(dispatch_get_main_queue(), ^{
                             [self didSectionframe:@"全部"];
                         });
                     }
                     else{
                    dispatch_async(dispatch_get_main_queue(), ^{
                     [self didSectionframe:groupArr[0][@"groupname"]];
                              });
                     }
                     dic[@"group"] = tmpGroup;
                     dic[@"groupNum"] = @0;
                     self.nowPlaydata = dic; // 找出当前的数据源
                     self.secondNumTextf.text = @"5";
                     if(!self.thumbScreen) self.thumbScreen = [NSMutableArray array];
                     if(self.thumbScreen.count-1 > nbtn)
                         [self.thumbScreen insertObject:dic atIndex:nbtn];
                     else
                         [self.thumbScreen addObject:dic];
                     if(!arr || [arr count] == 0){
                        [[MBProgressController sharedInstance] hide];
                         dispatch_async(dispatch_get_main_queue(),^{
                             [self eventNumData:-1 AllNUm:0];
                             wself.showImage.image = nil;
                             [[MBProgressController sharedInstance] showTipsOnlyText:@"当前屏幕暂无缩略图"                                                                            AndDelay:1.5];
                         });
                         NSLog(@"kong");
                     }
                     else{
                     [[MBProgressController sharedInstance] hide];
                     dispatch_async(dispatch_get_main_queue(),^{
                             [self eventNumData:collectionview.figureNum AllNUm:[arr count]];
                         
                         });
                         if([arr[0][@"width"] intValue] && [arr[0][@"height"] intValue]){
                     [wself.showImage setImage:[[DownloadImage sharedInstance] getUrlImage:StringFromId(arr[0][@"templateId"]) Block:^(UIImage *image){
                         [wself.showImage setImage:image];
                     }]];
                    [[TimerDownImage sharedInstance] downCallBackData:StringFromId(arr[0][@"templateId"]) CallBack:^(UIImage *image){
                             [wself.showImage setImage:image];
                        }];
                         }
                         else{
                        dispatch_async(dispatch_get_main_queue(),^{
                         wself.showImage.image = nil;
                            });
                             [[TimerDownImage sharedInstance] stopTimerDownImage];
                         }
                     }
                 }
                 failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                      [[MBProgressController sharedInstance] hide];
                     dispatch_async(dispatch_get_main_queue(), ^{
                         [[MBProgressController sharedInstance] hide];
                         [[MBProgressController sharedInstance] showTipsOnlyText:@"获取屏幕缩略图失败!" AndDelay:1.5];
                     });
                     NSLog(@"file");
                 }];
    });

}
//同步后台播放器的上下线
-(void)updateScreenDate:(NSString *)screenId ScreenDic:(NSMutableDictionary *)tmpdic Grouparr:(NSArray *)groupArr
{
    //[[MBProgressController sharedInstance] showWithText:@"正在努力加载....."];
    WeakSelf;
    //解析成组的字符串
    NSString *groupstring = nil;
    if(groupArr && [groupArr count]){
        for(NSDictionary *dic in groupArr){
            NSString *tmpstr;
            if([Common isEmptyString:groupstring])
                tmpstr = [NSString stringWithFormat:@"%@",dic[@"id"]];
            else
                tmpstr = [NSString stringWithFormat:@"%@,%@",groupstring,dic[@"id"]];
            groupstring = [NSString stringWithString:tmpstr];
        }
    }
//    else{
//        groupstring = StringFromId(groupArr[0]);
//    }
    
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSString *getScreenStr = [Network_API Network_API_GetScreen];
        AFHTTPClient *httpClient = [Network_Operation httpClientWithUrl:getScreenStr];
        NSDictionary *dic = @{
                              @"classname":@"iControlSolutionService",
                              @"methodname":@"getImageFromReveTemplateByGroupId",
                              @"parameterClasss":@[@{
                                                       @"parametername" :@"screenId",
                                                       @"parametervalue":screenId,
                                                       @"valuetype":@"java.lang.String"},
                                                   @{
                                                       @"parametername" :@"groupId",
                                                       @"parametervalue":groupstring,
                                                       @"valuetype":@"java.lang.String"
                                                       }
                                                   ]
                              };
        [httpClient postPath:getScreenStr parameters:@{@"jsonstr":[Common dictoJson:dic],
                                                       @"callback":@""
                                                       }
                     success:^(AFHTTPRequestOperation *operation, id responseObject) {
                         NSLog(@"success");
                         NSArray *arr = [Common jsontoArr:responseObject];
                         NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:self.thumbScreen[self.nowScreen]];
                         //获取缩略图
                         MJCollectionViewController *collection =  dic[@"collec"];
                         if(arr && [arr count]){
                             collection.thumbPage = [NSMutableArray arrayWithArray:arr];
                         }
                         else{
                             collection.thumbPage = [NSMutableArray array];
                         }
                         collection.thumbPage = [NSMutableArray array];
                         collection.thumbPage = [NSMutableArray arrayWithArray:arr];
                         collection.allPage = arr.count;
                         if(arr.count/collection.num)
                             collection.allPagenumber  = arr.count/collection.num +1 ;
                         else
                             collection.allPagenumber  = arr.count/collection.num;
                         [collection counstView:arr];
                         collection.flagplay = NO;
                         [collection.collectionView reloadData];
                         if(collection.allPagenumber > 1 )
                             self.pageView.numberOfPages = collection.allPagenumber;
                         else
                             self.pageView.numberOfPages = 0;
                         //停止播放
                         dic[StringFromInt(self.nowScreen)] = arr;
                         [self.thumbScreen removeObjectAtIndex:self.nowScreen];
                         
                         [self.thumbScreen insertObject:dic atIndex:self.nowScreen];
                         self.nowPlaydata = dic;
                         if(!arr || [arr count] == 0){
                             [[MBProgressController sharedInstance] hide];
                             dispatch_async(dispatch_get_main_queue(),^{
                                 [self eventNumData:-1 AllNUm:0];
                                 wself.showImage.image = nil;
                                 [[MBProgressController sharedInstance] showTipsOnlyText:@"当前主题无缩略图"
                                                                                AndDelay:1.5];
                             });
                             NSLog(@"kong");
                         }
                         else{
                             [[MBProgressController sharedInstance] hide];
                             dispatch_async(dispatch_get_main_queue(),^{
                                 [self eventNumData:collection.figureNum AllNUm:[arr count]];
                                 
                             });
                            if([arr[0][@"width"] intValue] && [arr[0][@"height"] intValue]){
                                 
                                 [wself.showImage setImage:[[DownloadImage sharedInstance] getUrlImage:StringFromId(arr[0][@"templateId"]) Block:^(UIImage *image){
                                     [wself.showImage setImage:image];
                                 }]];
                                 [[TimerDownImage sharedInstance] downCallBackData:StringFromId(arr[0][@"templateId"]) CallBack:^(UIImage *image){
                                     [wself.showImage setImage:image];
                                 }];
                             }
                             else{
                                 dispatch_async(dispatch_get_main_queue(),^{
                                     wself.showImage.image = nil;
                                 });
                                 [[TimerDownImage sharedInstance] stopTimerDownImage];
                             }
                         }
                          dic[@"proharr"] = [NSArray array];
                     }
                     failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                         [[MBProgressController sharedInstance] hide];
                         dispatch_async(dispatch_get_main_queue(), ^{
                             [[MBProgressController sharedInstance] hide];
                             [[MBProgressController sharedInstance] showTipsOnlyText:@"获取屏幕缩略图失败!" AndDelay:1.5];
                         });
                         NSLog(@"file");
                     }];
    });
    
}
//屏幕下的所有分组
-(void)getScreenGroup:(NSString *)screenId Numscreen:(NSInteger)nbtn
{
 //   [[MBProgressController sharedInstance] showWithText:@"正在努力加载....."];
    WeakSelf;
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSString *getScreenStr = [Network_API Network_API_GetScreen];
        AFHTTPClient *httpClient = [Network_Operation httpClientWithUrl:getScreenStr];
        NSDictionary *dic = @{
                              @"classname":@"iControlSolutionService",
                              @"methodname":@"getReveTemplateGroup",
                              @"parameterClasss":@[@{
                                                       @"parametername" :@"screenId",
                                                       @"parametervalue":screenId,
                                                       @"valuetype":@"java.lang.String"}
                                                   ]
                              };
        [httpClient getPath:getScreenStr parameters:@{@"jsonstr":[Common dictoJson:dic],
                                                       @"callback":@""
                                                       }
                     success:^(AFHTTPRequestOperation *operation, id responseObject) {
                        
                         NSArray *arr = [Common jsontoArr:responseObject];
                         [wself getScreenImage:screenId Numscreen:nbtn GroupArr:arr];
                     }
                     failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                
                     }];
    });
    
}
//点击分组的下拉框的按钮
-(void)getGroupThumb:(NSString *)screenId Grouparr:(NSArray *)groupArr Btnnum:(NSInteger)nbtn
{
    [[MBProgressController sharedInstance] showWithText:@"正在努力加载....."];
    WeakSelf;
    //解析成组的字符串
    NSString *groupstring = nil;
    if(groupArr && [groupArr count]){
        for(NSDictionary *dic in groupArr){
            NSString *tmpstr;
            if([Common isEmptyString:groupstring])
                tmpstr = [NSString stringWithFormat:@"%@",dic[@"id"]];
            else
                tmpstr = [NSString stringWithFormat:@"%@,%@",groupstring,dic[@"id"]];
            groupstring = [NSString stringWithString:tmpstr];
        }
    }
    
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSString *getScreenStr = [Network_API Network_API_GetScreen];
        AFHTTPClient *httpClient = [Network_Operation httpClientWithUrl:getScreenStr];
        NSDictionary *dic = @{
                              @"classname":@"iControlSolutionService",
                              @"methodname":@"getImageFromReveTemplateByGroupId",
                              @"parameterClasss":@[@{
                                                       @"parametername" :@"screenId",
                                                       @"parametervalue":screenId,
                                                       @"valuetype":@"java.lang.String"},
                                                   @{
                                                       @"parametername" :@"groupId",
                                                       @"parametervalue":groupstring,
                                                       @"valuetype":@"java.lang.String"
                                                       }
                                                   ]
                              };
        
        [httpClient postPath:getScreenStr parameters:@{@"jsonstr":[Common dictoJson:dic],
                                                       @"callback":@""
                                                       }
                     success:^(AFHTTPRequestOperation *operation, id responseObject) {
                         NSLog(@"success");
                      //   dispatch_async(dispatch_get_main_queue(), ^{
                             [[MBProgressController sharedInstance] hide];
                     //    });
                         NSArray *arr = [Common jsontoArr:responseObject];
                         NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:self.thumbScreen[self.nowScreen]];
                         //获取缩略图
                         MJCollectionViewController *collection =  dic[@"collec"];
                         if(arr && [arr count]){
                             collection.thumbPage = [NSMutableArray arrayWithArray:arr];
                         }
                         else{
                             collection.thumbPage = [NSMutableArray array];
                         }
                         collection.thumbPage = [NSMutableArray array];
                         collection.thumbPage = [NSMutableArray arrayWithArray:arr];
                         collection.allPage = arr.count;
                         if(arr.count%collection.num)
                             collection.allPagenumber  = arr.count/collection.num +1 ;
                         else
                             collection.allPagenumber  = arr.count/collection.num;
                         [collection counstView:arr];
                         collection.flagplay = NO;
                         [collection.collectionView reloadData];
                         [self.collView addSubview:collection.view];
                         [self.collView bringSubviewToFront:collection.view];
                        if(collection.allPagenumber > 1)
                        self.pageView.numberOfPages = collection.allPagenumber;
                        else
                        self.pageView.numberOfPages = 0;
                         //停止播放
                         dic[StringFromInt(self.nowScreen)] = arr;
                         dic[@"noArrowplay"] = @"0";
                         dic[@"noOnceplay"] = @"0";
                         dic[@"startqueue"] = @"0";
                         dic[@"groupNum"] = StringFromInt(nbtn);
                         dic[@"proharr"] = [NSArray array];
                         dic[@"noOpen"] = @0;
                         if([arr count] <= CLOSEPAGE)
                          [self closeThumbView];
                         [self.arrowplay setBackgroundImage:[UIImage imageNamed:@"scan_arrowplay.png"] forState:UIControlStateNormal];
                         [self.onceplay setBackgroundImage:[UIImage imageNamed:@"scan_onceplay.png"] forState:UIControlStateNormal];
                         
                         [self.thumbScreen removeObjectAtIndex:self.nowScreen];
                         
                         [self.thumbScreen insertObject:dic atIndex:self.nowScreen];
                         self.nowPlaydata = dic;
                         if(!arr || [arr count] == 0){
                             [[MBProgressController sharedInstance] hide];
                             dispatch_async(dispatch_get_main_queue(),^{
                                 [self eventNumData:-1 AllNUm:0];
                                 wself.showImage.image = nil;
                                 [[MBProgressController sharedInstance] showTipsOnlyText:@"当前主题无缩略图"
                                                                                AndDelay:1.5];
                             });
                             NSLog(@"kong");
                         }
                         else{
                             [[MBProgressController sharedInstance] hide];
                             dispatch_async(dispatch_get_main_queue(),^{
                                 [self eventNumData:collection.figureNum AllNUm:[arr count]];
                                 
                             });
                         if([arr[0][@"width"] intValue] && [arr[0][@"height"] intValue]){
                                 
                                 [wself.showImage setImage:[[DownloadImage sharedInstance] getUrlImage:StringFromId(arr[0][@"templateId"]) Block:^(UIImage *image){
                                     [wself.showImage setImage:image];
                                 }]];
                                 [[TimerDownImage sharedInstance] downCallBackData:StringFromId(arr[0][@"templateId"]) CallBack:^(UIImage *image){
                                     [wself.showImage setImage:image];
                                 }];
                             }
                             else{
                                 dispatch_async(dispatch_get_main_queue(),^{
                                     wself.showImage.image = nil;
                                 });
                                 [[TimerDownImage sharedInstance] stopTimerDownImage];
                             }
                         }
                         
                     }
                     failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                         [[MBProgressController sharedInstance] hide];
                         dispatch_async(dispatch_get_main_queue(), ^{
                             [[MBProgressController sharedInstance] hide];
                             [[MBProgressController sharedInstance] showTipsOnlyText:@"获取屏幕缩略图失败!" AndDelay:1.5];
                         });
                         NSLog(@"file");
                     }];
    });

}

-(void)getGroupThumbno:(NSString *)screenId Grouparr:(NSArray *)groupArr Btnnum:(NSInteger)nbtn
{
   // [[MBProgressController sharedInstance] showWithText:@"正在努力加载....."];
    WeakSelf;
    //解析成组的字符串
    NSString *groupstring = nil;
    if(groupArr && [groupArr count]){
        for(NSDictionary *dic in groupArr){
            NSString *tmpstr;
            if([Common isEmptyString:groupstring])
                tmpstr = [NSString stringWithFormat:@"%@",dic[@"id"]];
            else
                tmpstr = [NSString stringWithFormat:@"%@,%@",groupstring,dic[@"id"]];
            groupstring = [NSString stringWithString:tmpstr];
        }
    }
    
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSString *getScreenStr = [Network_API Network_API_GetScreen];
        AFHTTPClient *httpClient = [Network_Operation httpClientWithUrl:getScreenStr];
        NSDictionary *dic = @{
                              @"classname":@"iControlSolutionService",
                              @"methodname":@"getImageFromReveTemplateByGroupId",
                              @"parameterClasss":@[@{
                                                       @"parametername" :@"screenId",
                                                       @"parametervalue":screenId,
                                                       @"valuetype":@"java.lang.String"},
                                                   @{
                                                       @"parametername" :@"groupId",
                                                       @"parametervalue":groupstring,
                                                       @"valuetype":@"java.lang.String"
                                                       }
                                                   ]
                              };
        
        [httpClient postPath:getScreenStr parameters:@{@"jsonstr":[Common dictoJson:dic],
                                                       @"callback":@""
                                                       }
                     success:^(AFHTTPRequestOperation *operation, id responseObject) {
                         NSLog(@"success");
                         dispatch_async(dispatch_get_main_queue(), ^{
                             //[[MBProgressController sharedInstance] hide];
                         });
                         NSArray *arr = [Common jsontoArr:responseObject];
                         NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:self.thumbScreen[self.nowScreen]];
                         //获取缩略图
                         MJCollectionViewController *collection =  dic[@"collec"];
                         if(arr && [arr count]){
                             collection.thumbPage = [NSMutableArray arrayWithArray:arr];
                         }
                         else{
                             collection.thumbPage = [NSMutableArray array];
                         }
                         collection.thumbPage = [NSMutableArray array];
                         collection.thumbPage = [NSMutableArray arrayWithArray:arr];
                         collection.allPage = arr.count;
                         if(arr.count%collection.num)
                             collection.allPagenumber  = arr.count/collection.num +1 ;
                         else
                             collection.allPagenumber  = arr.count/collection.num;
                         [collection counstView:arr];
                         collection.flagplay = NO;
                         [collection.collectionView reloadData];
                         [self.collView addSubview:collection.view];
                         [self.collView bringSubviewToFront:collection.view];
                         if(collection.allPagenumber > 1)
                         self.pageView.numberOfPages = collection.allPagenumber;
                         else
                         self.pageView.numberOfPages = 0;
                         //停止播放
                         dic[StringFromInt(self.nowScreen)] = arr;
                         dic[@"noArrowplay"] = @"0";
                         dic[@"noOnceplay"] = @"0";
                         dic[@"startqueue"] = @"0";
                         dic[@"groupNum"] = StringFromInt(nbtn);
                         dic[@"proharr"] = [NSArray array];
                         dic[@"noOpen"] = @0;
                         if([arr count] <= CLOSEPAGE)
                             [self closeThumbView];
                         [self.arrowplay setBackgroundImage:[UIImage imageNamed:@"scan_arrowplay.png"] forState:UIControlStateNormal];
                         [self.onceplay setBackgroundImage:[UIImage imageNamed:@"scan_onceplay.png"] forState:UIControlStateNormal];
                         
                         [self.thumbScreen removeObjectAtIndex:self.nowScreen];
                         
                         [self.thumbScreen insertObject:dic atIndex:self.nowScreen];
                         self.nowPlaydata = dic;
                         if(!arr || [arr count] == 0){
                            // [[MBProgressController sharedInstance] hide];
                             dispatch_async(dispatch_get_main_queue(),^{
                                 [self eventNumData:-1 AllNUm:0];
                                 wself.showImage.image = nil;
//                                 [[MBProgressController sharedInstance] showTipsOnlyText:@"当前主题无缩略图"
//                                                                                AndDelay:1.5];
                             });
                             NSLog(@"kong");
                         }
                         else{
                             //[[MBProgressController sharedInstance] hide];
                             dispatch_async(dispatch_get_main_queue(),^{
                                 [self eventNumData:collection.figureNum AllNUm:[arr count]];
                                 
                             });
                         if([arr[0][@"width"] intValue] && [arr[0][@"height"] intValue]){
                                 
                                 [wself.showImage setImage:[[DownloadImage sharedInstance] getUrlImage:StringFromId(arr[0][@"templateId"]) Block:^(UIImage *image){
                                     [wself.showImage setImage:image];
                                 }]];
                                 [[TimerDownImage sharedInstance] downCallBackData:StringFromId(arr[0][@"templateId"]) CallBack:^(UIImage *image){
                                     [wself.showImage setImage:image];
                                 }];
                             }
                             else{
                                 dispatch_async(dispatch_get_main_queue(),^{
                                     wself.showImage.image = nil;
                                 });
                                 [[TimerDownImage sharedInstance] stopTimerDownImage];
                             }
                         }
                         
                     }
                     failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                         //[[MBProgressController sharedInstance] hide];
                         dispatch_async(dispatch_get_main_queue(), ^{
                             [[MBProgressController sharedInstance] hide];
                             [[MBProgressController sharedInstance] showTipsOnlyText:@"获取屏幕缩略图失败!" AndDelay:2.0];
                         });
                         NSLog(@"file");
                     }];
    });
}
@end
